﻿using System.Collections.Generic;
using System.IO;
using System;
using System.Xml;

using Ch.Admin.Bfs.Sms.Sdmx.Common;
using Ch.Admin.Bfs.Sms.Sdmx.Schemes;
using Ch.Admin.Bfs.Sms.Sdmx.Utils;
using Ch.Admin.Bfs.Sms.Sdmx.IO.Xml;
using Ch.Admin.Bfs.Sms.Sdmx.Registry;

using SdmxMl.Manager;
using SdmxMl.Structure;
using SdmxMl.Common;

namespace SdmxMl.Manager
{
    //public class ArtefactChecker
    //{

    //    private static TinyArtefactRegistry registry;

    //    public List<SdmxInformationMessage> Check(Artefact a)
    //    {
    //        List<SdmxInformationMessage> diagList = new List<SdmxInformationMessage>();
            
    //        registry = new TinyArtefactRegistry();
    //     //   RegistryUtils.ArtefactRegistry = registry;

    //        try
    //        {
    //            SmManager sm = new SmManager();
    //            sm.PutArtefact(a.ArType, a);


    //            XmlDocument xmlDoc = sm.GetArtefactAsDocument(a.ArType, a); ;
    //            MemoryStream xmlStream = new MemoryStream();
    //            xmlDoc.Save(xmlStream);
    //            xmlStream.Flush();
    //            xmlStream.Position = 0;

    //            if (a.ArType != SdmxArtefactType.MetadataSet)
    //            {
    //                StructureMessage msg = SdmxXmlUtil.ReadMessage(xmlStream) as StructureMessage;
    //                MaintainableArtefact ma = msg.Artefacts[0];
    //                diagList = SdmxXmlUtil.CheckArtefact(ma, Ch.Admin.Bfs.Sms.Sdmx.Xml.SdmxVersion.SDMX_2_1, registry);
    //            }
    //            else
    //            {
    //                Ch.Admin.Bfs.Sms.Sdmx.Metadata.MetadataSet metaset = registry.GetMetaSet(a.FullIdent);
    //                diagList = SdmxXmlUtil.CheckArtefact(metaset, Ch.Admin.Bfs.Sms.Sdmx.Xml.SdmxVersion.SDMX_2_1, registry);
    //            }
    //        }
    //        catch (Exception ex)
    //        {
    //            throw new RegistryException("Unable to check " + a.FullIdent, ex);
    //        }


    //        return diagList;
    //    }
    //}
}
